home *** CD-ROM | disk | FTP | other *** search
- /* Iconic LDEF.c */
- /*
- * All of the list-drawing nitty-gritty is here.
- * Each list cell contains an icon and the icon id.
- * Either draw the icon in the cell rectangle or convert
- * the icon id to hex and draw that string.
- *
- * Copyright © 1989, 1990 Martin Minow and MacTutor.
- */
- #include "IconicLDEF.h"
-
- void iconicLDEF(Rect *, Cell, short, short, ListHandle);
- static void DrawHex(unsigned short, short);
-
- /*
- * iconicLDEF() is called by the LDEF handler to draw
- * an icon whose resource ID is stored in the cell.
- */
- void
- iconicLDEF(rect, cell, offset, length, list)
- Rect *rect; /* Rectangle to draw cell in */
- Cell cell; /* The selected cell */
- short offset; /* Start of data in the list */
- short length; /* Number of bytes to draw */
- ListHandle list; /* The list itself. */
- {
- IconInfo iconInfo;
-
- /*
- * Note that we ignore zero-length (empty) cells.
- */
- if (length == sizeof iconInfo) {
- LGetCell(&iconInfo, &length, cell, list);
- /*
- * Show we can access the global parameter. Of
- * course, a "real" application would use a
- * document-specific data structure, probably
- * accessed via the document structure or window
- * refCon. Using this global is actually incorrect
- * as partial window updates will leave a list cell
- * half in one format and half in the other.
- */
- if (drawAsText)
- DrawHex(iconInfo.number, sizeof (short) * 2);
- else {
- if (iconInfo.handle != NIL) {
- PlotIcon(rect, iconInfo.handle);
- }
- }
- }
- }
-
- /*
- * Recursive routine to draw a value in hex.
- * Each call of DrawHex outputs one nibble.
- */
- static void
- DrawHex(hex, size)
- unsigned short hex;
- short size;
- {
- if (--size > 0)
- DrawHex(hex >> 4, size);
- hex &= 0x0f;
- DrawChar((hex >= 10) ? hex - 10 + 'a' : hex + '0');
- }
-